package editeur;

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.*;
import java.io.File;
import java.io.Serializable;

import javax.imageio.ImageIO;
import javax.swing.JFileChooser;


public class Photo  extends BufferedImage implements Serializable{

	

	/**
	 * 
	 */
	private static final long serialVersionUID = 1764482787482625146L;
	private String nom;
	
	
	public Photo(String nom,BufferedImage img){
		super(img.getWidth(),img.getHeight(),BufferedImage.TYPE_INT_RGB);
		this.setData(img.getData());
       this.nom=nom;
		
	}
	

	

	
	public  void Load() {  
        BufferedImage bimg = null; 
        String ref;
        JFileChooser fc = new JFileChooser();
        File file=null;
        int returnVal=fc.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION)
        {
        	file = fc.getSelectedFile();
        	ref=file.getAbsolutePath();
        	 try {  
                 bimg = ImageIO.read(new File(ref));  
             } catch (Exception e) {  
                 e.printStackTrace();  
             }        
        }
        this.setData(bimg.getData());
       
    }

    public void resize(BufferedImage img, int newW, int newH) {  
        int w = img.getWidth();  
        int h = img.getHeight();  
        BufferedImage dimg = new BufferedImage(newW, newH, img.getType());  
        Graphics2D g = dimg.createGraphics();  
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);  
        g.drawImage(img, 0, 0, newW, newH, 0, 0, w, h, null);  
        g.dispose();  
        img=dimg;  
    }  


	  
	public String getNom(){
		return nom;
	}

}
